<template>
  <transition name="fade">
    <div class="toast" v-if="isShow">
      {{message}}
    </div>
  </transition>
</template>

<script>
  export default {
    name: "Toast",
    data() {
      return {
        isShow: false,
        message: ''
      }
    },
    methods: {
      show(message = "message", duration = 1000) {
        this.isShow = true;
        this.message = message;
        setTimeout(() => {
          this.isShow = false;
          this.message = '';
        }, duration)
      }
    }
  }
</script>

<style scoped>
  .toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, .75);
    z-index: 10001;
    padding: 20px;

    color: #fff;
  }
</style>
